<template>
	<view class="distributor">
		<view class="cover">
			<image mode="widthFix" class="bg" :src="cover_bg"></image>
			<view class="avatar">
				<open-data class="image" type="userAvatarUrl"></open-data>
				<open-data class="name" type="userNickName"></open-data>

			</view>



		</view>

		<template v-if="mode=='distribution'" >
			<view class="apply" v-if="!info">
				<u-button class="apply-btn" v-on:click="apply_distributor()">申请成为分销商</u-button>
			</view>
			
			<view class="apply" v-if="info && info.distributor_status==2">
				<view>分销商申请未通过</view>
			</view>
			
			<view class="apply" v-if="info && info.distributor_status==0">
				<view>分销商申请审核中</view>
			</view>
		</template>
		

		<!-- <view class="menu" v-if="info && info.distributor_status==1"> -->
		<view class="menu" v-if="mode=='distribution_yiyang' || info && info.distributor_status==1" >

			<navigator class="item" 
				v-if="mode=='distribution_yiyang'"
				url="/sm_shop/pages/distributor/yiyang_card">
				<view class="icon">
					<u-icon name="man-add-fill"></u-icon>
				</view>
				<view class="name">
					分销会员卡
				</view>
				<view v-if="yiyang_card_has_hehuoren" class="">合伙人</view>
				<view v-else-if="yiyang_card_has_xiaofeizhe" class="">消费者</view>
				<view class="arrow"></view>
			</navigator>
			
			<view class="item"
				v-if="mode=='distribution_yiyang'" >
				<view class="icon">
					<u-icon name="man-add-fill"></u-icon>
				</view>
				<view class="name">
					代理级别
				</view>
				<view v-if="yiyang_agent" class="">
					<text>{{yiyang_agent.agent_name_text}}</text>
				</view>
				<view v-else="" class="">无</view>
			</view>
			
			
			<navigator class="item" url="/sm_shop/pages/distributor/referrals">
				<view class="icon">
					<u-icon name="man-add-fill"></u-icon>
				</view>
				<view class="name">
					我的下线
				</view>
				<view class="arrow"></view>
			</navigator>
			
			<!--
			<navigator class="item" url="/sm_shop/pages/distributor/order">
				<view class="icon">
					<u-icon name="rmb" ></u-icon>
				</view>
				<view class="name">
					我的分销
				</view>
				<view class="arrow"></view>
			</navigator>
			-->
			
			<navigator class="item" url="/sm_shop/pages/distributor/cash-out">
				<view class="icon">
					<u-icon name="rmb" ></u-icon>
				</view>
				<view class="name">
					我的提现
				</view>
				<view class="arrow"></view>
			</navigator>
			
			<navigator class="item" url="/sm_shop/pages/distributor/rule">
				<view class="icon">
					<u-icon name="rmb" ></u-icon>
				</view>
				<view class="name">
					分销规则
				</view>
				<view class="arrow"></view>
			</navigator>
			
			<!--
			<navigator class="item" url="/sm_shop/pages/distributor/history">
				<view class="icon">
					<u-icon name="rmb" ></u-icon>
				</view>
				<view class="name">
					分销记录
				</view>
				<view class="arrow"></view>
			</navigator>
			-->


		</view>

	</view>
</template>

<script>
	const appInstance = getApp();
	export default {
		data() {
			return {
				cover_bg: '',
				mode:'distribution', // 分销模式，distribution：普通, distribution_yiyang:医养分销
				info: false,
				yiyang_card:[],
				yiyang_agent:null,
				yiyang_card_has_hehuoren:0,
				yiyang_card_has_xiaofeizhe:0
			}
		},
		onLoad(options) {
			var that = this;
			var host = appInstance.globalData.api_host.split('/app')[0];
			this.cover_bg = appInstance.globalData.customer_bg_img;
			appInstance.globalData.checkUserStatus();
			this.init(options);
		},
		onPullDownRefresh() {
			this.init();
			setTimeout(function () {
			    uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {

			init: function(options) {

				this.get_info();
			},

			get_info: function() {
				var t = this;
				var url = '&r=distribution.info';

				appInstance.globalData.request(url, {
					m: 'sm_shop_plugin_distribution'
				}, 'GET', function(res) {
					
					t.mode = res.data.mode;
					if( t.mode == 'distribution'){
						t.info = res.data.distribution;
					}
					if( t.mode == 'distribution_yiyang'){
						t.yiyang_agent = res.data.yiyang_agent;
						t.yiyang_card = res.data.yiyang_card;
						t.yiyang_card_has_hehuoren = res.data.yiyang_card_has_hehuoren;
						t.yiyang_card_has_xiaofeizhe = res.data.yiyang_card_has_xiaofeizhe;
					}
				});
			},

			// todo 申请成为分销商
			apply_distributor: function() {

				var t = this;
				var url = '&r=distribution.apply';

				appInstance.globalData.request(url, {
					m: 'sm_shop_plugin_distribution'
				}, 'GET', function(res) {

					t.get_info();

				});

			}
		}
	}
</script>

<style lang="less">
	@import './distributor.less';
</style>
